#include "stdafx.h"
#include "CardLevelup.h"
#include "InstanceTouch.h"

DECL_INSTANCE_TOUCH(ETouch_LevelupExp);

struct  CardLevelUpExpReflectionRegister
{
	CardLevelUpExpReflectionRegister()
	{
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iID,INVALID_ID).Editor_SetAsPrimaryKey();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_sDisplayName,std::string("DefaultName")).Editor_SetAsDisplayName();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iLevel,1).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iStar1,uint32(1)).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iStar2,uint32(1)).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iStar3,uint32(1)).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iStar4,uint32(1)).Editor_SetAsRaw();
		REGISTER_REFLECTION_MEMBER(CardLevelUpExp,m_iStar5,uint32(1)).Editor_SetAsRaw();

		GlobalClassManager::Instance().RegisterClass(CardLevelUpExp::s_GetReflection(),eDefaultDef_CardLevelUpExp);
		GlobalDefManager::Instance().RegisterDefManger(&CardLevelUpExpManager::Instance());
	}
}___cardlevelupexpreflectionregister;


rewrite  void CardLevelUpExp::OnArchieveReaded()
{
	m_vLevelUpNeedExp[0]=0;
	m_vLevelUpNeedExp[1]=m_iStar1;
	m_vLevelUpNeedExp[2]=m_iStar2;
	m_vLevelUpNeedExp[3]=m_iStar3;
	m_vLevelUpNeedExp[4]=m_iStar4;
	m_vLevelUpNeedExp[5]=m_iStar5;
}
CardLevelUpExpManager::CardLevelUpExpManager()
{
	memset(m_vLevelupExpArray,0,sizeof(m_vLevelupExpArray));
}

rewrite  void CardLevelUpExpManager::OnArchieveReaded()
{
	__CardLevelUpExpManager::OnArchieveReaded();
	
	memset(m_vLevelupExpArray,0,sizeof(m_vLevelupExpArray));
	std::vector<const CardLevelUpExp*> vLevels;
	Enumerate(vLevels);
	for(uint32 ii=0;ii<vLevels.size();ii++)
	{
		const CardLevelUpExp* pLevel=vLevels[ii];
		if(pLevel->m_iLevel<0 ||pLevel->m_iLevel>cu_MaxLevel) continue;
		m_vLevelupExpArray[pLevel->m_iLevel]=pLevel;
	}
}

uint32 CardLevelUpExpManager::GetLevelUpExp( uint32 iStart,uint32 icurLevel )
{
	if(iStart>5 || icurLevel>cu_MaxLevel) return 0;
	const CardLevelUpExp* pLevel =m_vLevelupExpArray[icurLevel];
	if(pLevel==NULL) return 0;
	return pLevel->m_vLevelUpNeedExp[iStart];
}